package coding;

public class AttackControl
{
    private String MonsterName;
    private String HunterName;
    private MonsterHunter h;
    private Monster m;

    private double weakStrengthSystem(String s1, String s2)
    {
        if(s1=="Melee" && s2=="Ranger" || s1=="Ranger"&& s2=="Mage" || s1=="Mage"&& s2=="Melee")
            return 1.5;
        else if(s2=="Melee" && s1=="Ranger" || s2=="Ranger"&& s1=="Mage" || s2=="Mage"&& s1=="Melee")
            return 0.5;
        else
            return 1;
    }
    
    public AttackControl(MonsterHunter h1,Monster m1)
    {
        MonsterName=m1.getName();
        HunterName=h1.getName();    
        h=h1;
        m=m1;
    }        

    public String attackfromMH()
    {
        int damage =h.getAttack();
        String attackSide=h.getJob();
        String hurtSide=m.getJob();
        double newDamage = weakStrengthSystem(attackSide, hurtSide) * damage;
        damage=(int)newDamage;
        m.hurted(damage);    
        String s=HunterName+ " attack " + MonsterName+ " for " + damage + " life. \n";
        if(!m.isAlive())
        {
            s=s+ MonsterName+ " was dead. " +HunterName + " earned "     +m.getExp()+ " exp. \n";
            if(h.islevelup(m.getExp()))
            {
                s= s+ HunterName + " level Up  \n";
            }
        }
        else
            s=s +MonsterName+ " now remains " +m.getLife()+ " life.";     
        return s;
    }
    
    public String attackfromMonster()
    {
        int damage=m.getAttack();
        String attackSide=m.getJob();
        String hurtSide=h.getJob();
        double newDamage = weakStrengthSystem(attackSide, hurtSide) * damage;
        damage=(int)newDamage;
        String s= MonsterName+ " attack "+ HunterName+"  for " + damage + " life. \n";
        h.hurt(damage);
        if (!h.isAlive())
            s=s+HunterName + " dead. \n";
        else
            s=s +HunterName + " now remains " +h.getLife()+ " life. \n";
        return s;
    }
}
